package com.order.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * description:权限配置
 *
 * @author yang
 * @date 2019/7/29 10:19
 */
@Configuration
public class OAuth2ServerConfiguration {

  private static final String RESOURCE_ID = "order";

  @Configuration
  @EnableResourceServer
  protected static class ResourceServerConfiguration extends
      ResourceServerConfigurerAdapter {

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
      // @formatter:off
      resources.resourceId(RESOURCE_ID);
      // @formatter:on
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
      // @formatter:off

      http.headers().frameOptions().disable().and()
          .authorizeRequests()
          //用户
          .antMatchers(HttpMethod.POST, "/**").authenticated()
          .antMatchers("/applet/**").permitAll()
          .and().csrf().disable();
      // @formatter:on
    }
  }
}
